<template>
  <view class="check-container">
    <view
      :class="{ 'title-text': true, 'line-text': !!data.status }"
      @click="view"
    >
      <view class="title-text-title">
        <u-loading
          v-if="loading"
          mode="circle"
          size="24"
          color="#2979ff"
        ></u-loading>
        <view
          v-else
          class="check-view"
          :style="{ backgroundColor: data.status ? '#2979ff' : '' }"
          @tap.stop="handleCheck"
        >
          <u-icon
            name="checkbox-mark"
            color="#fff"
            size="20"
            v-show="data.status"
          ></u-icon>
        </view>
        <text class="title-text-title-text">{{ data.title }}</text>
        <u-tag :text="data.classification.name" shape="square" size="mini" />
      </view>
      <view class="title-text-content">{{ data.content }}</view>
      <view class="bottom-area">
        <view v-if="data.status">{{ data.complete_time }}</view>
        <view v-else-if="data.process" class="title-text-process"
          >最新进展：{{ data.process.content }}</view
        ><view v-else>暂无进展</view>
        <view class="more-icon" @tap.stop="toHandleMenu"
          ><u-icon name="more-dot-fill" size="28"></u-icon
        ></view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted, onBeforeUnmount } from "vue";
// 定义props
const props = defineProps({
  data: {
    type: Object,
    required: true,
  },
});

const emit = defineEmits(["handleMenu", "handleCheck"]);

//loading
const loading = ref(false);

// 完成/未完成代办
const handleCheck = async () => {
  loading.value = true;
  emit("handleCheck", {
    data: props.data,
    complete: () => {
      loading.value = false;
    },
  });
};

// 查看详情
const view = () => {
  uni.vk.navigateTo({
    url: `/subPages/todo/detailView?id=${props.data._id}`,
  });
};

const toHandleMenu = () => {
  emit("handleMenu");
};
</script>

<style scoped lang="scss">
.check-container {
  width: 100%;
  margin-bottom: 10px;
  box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  position: relative;

  .title-text {
    padding: 10px;
    background-color: #ffffff;
    border-radius: 4px;
    width: 100%;

    .title-text-title {
      display: flex;
      align-items: center;
      color: $u-main-color;
      // margin-bottom: 5px;
      .check-view {
        box-sizing: content-box;
        width: 14px;
        height: 14px;
        border: 1px solid $u-type-primary;
        border-radius: 3px;
        position: relative;
        .u-icon {
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
        }
      }
      & > text {
        margin-left: 10px;
        font-weight: 600;
        flex: 1;
      }
    }

    .title-text-content {
      color: $u-content-color;
      font-size: 0.9em;
      margin: 8px 0 4px 27px;
      width: calc(100% - 27px);
    }
  }

  .line-text {
    .title-text-title {
      .title-text-title-text {
        text-decoration: line-through;
        color: $u-content-color;
      }
    }
  }

  .bottom-area {
    font-size: 0.8em;
    color: $u-tips-color;
    margin-top: 10px;
    padding: 5px 2px 0px 2px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    & > view:first-child {
      flex: 1;
    }
    .more-icon {
      margin-left: 5px;
      color: $u-tips-color;
      background: #fff;
      width: 2em;
      height: 1.5em;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}
</style>
